using AspectCore.Configuration;
using AspectCore.Extensions.DependencyInjection;
using AspectCoreDemo.Transaction.Host.Infrastructures;
using AspectCoreDemo.Transaction.Host.Models;
using AspectCoreDemo.Transaction.Host.Repositories;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<AppDbContext>(options =>
{
    options.UseMySQL(builder.Configuration.GetConnectionString("Default")!);
});
builder.Services.AddTransient<IOrderRepository, OrderRepository>();
builder.Services.ConfigureDynamicProxy(config =>
{
    config.Interceptors.AddTyped<TransactionInterceptorAttribute>();
});

var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();